<?php
/**
 * Created by PhpStorm.
 * User: cc
 * Date: 2023/10/16
 * Time: 1:57 PM
 */

namespace app\zyhsapi\model;

use think\Log;
use XznsTools\cache\zyhs\CacheManageZyhs;

class ZyhsVrtualuserComment extends BaseCacheZyhs
{
    protected $table = 'good_wechat.zyhs_vrtualuser_comment';
    protected $cacheModel = 'zyhs.vrtualuser_comment';

    /**
     * 虚拟评论列表
     * @return array
     * @throws \Exception
     */
    public function commentList($field)
    {
        $ids = CacheManageZyhs::getInstance()->setCacheConfig($this->cacheModel)->setSort('DESC')->ZsGetIocData('list', function ()
        {
            try
            {
                $ids = $this->where('status', 1)->column('id');
                return array_flip_key_value($ids);
            }
            catch (\Exception $e)
            {
                Log::write('ZyhsVrtualuserComment model => ()异常：' . $e->getMessage() . '失败信息：' . $e->getFile() . ':' . $e->getLine(), 'error', true);
            }
        });
        return $this->batchGetInfo($ids, $field);
    }

    public function batchGetInfo($cids, $field = [])
    {
        $data = $this->batchGetInfoByIds($cids, $field);
        foreach ($data as $key => $datum)
        {
            if (isset($datum['tids']))
            {
                $data[$key]['tids'] = explode(',', $datum['tids']);
            }
        }
        return $data;
    }


    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        try
        {
            $data = $this->where(['id' => ['in', $ids]])->column('*', 'id');
        }
        catch (\Exception $e)
        {
            $data = [];
        }
        return $data;
    }
}
